package cn.web.management.web.servlet.resource;

import cn.web.management.domain.UserState;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "headPortraitServlet", value = "/headPortraitServlet")
public class headPortraitServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        UserState userState = (UserState)session.getAttribute("userState");
        if (userState != null) {
            String userPortrait = userState.getUserPortrait();
            resp.getWriter().write(userPortrait);
        }
        else
            resp.getWriter().write("default");
    }
}
